package com.sun.services.roles.repository;

import com.sun.dto.users.PermissionDto;
import com.sun.entitys.users.Permission;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface PermissionRepository extends CrudRepository<Permission, Long> {
    @Query("""
            SELECT new com.sun.dto.users.PermissionDto(p.id, p.name, p.code, p.menuId, p.controller, p.method) FROM Permission p 
            left join  RolePermission rp on p.id = rp.permissionId
                        WHERE p.deleted = 0 and  rp.roleId = :roleId and  rp.deleted = 0
            """)
    List<PermissionDto> findAllByRoleId(Long roleId);
}
